﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using BLL;
using DAL;

namespace IAATO
{
    /// <summary>
    /// Description résumée de ProgrammeWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // Pour autoriser l'appel de ce service Web depuis un script à l'aide d'ASP.NET AJAX, supprimez les marques de commentaire de la ligne suivante. 
    [System.Web.Script.Services.ScriptService]
    public class ProgrammeWebService : System.Web.Services.WebService
    {
        JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        ActiviteService activiteService = new ActiviteService(new ActiviteManager(), new SiteManager());
        ProgrammeService programmeService = new ProgrammeService(new ProgrammeManager());
        CreneauService creneauService = new CreneauService(new CreneauManager());

        [WebMethod]
        public string getSiteInfo(int siteId, int jour, int mois, int annee)
        {
            DateTime date = new DateTime(annee, mois, jour);

            var activites = from a in activiteService.getActivitesOnSite(siteId)
                            select new { nom = a.NOM };

            var programmesIds = from p in programmeService.getProgrammesAtDate(date)
                                select p.ID;

            var creneaux = from c in creneauService.getAllCreneaux()
                           where programmesIds.Contains(c.PROGRAMMEID) && c.SITEID == siteId
                           select new { ordre = c.ORDRE };

            var response = new { activites = activites, creneaux = creneaux };

            return serializer.Serialize(response);
        }
    }
}
